package com.bluebridgecup.SearchBasics;

import java.util.Scanner;

public class 蛋糕的美味值 {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        // 有n个蛋糕，最大美味值为k
        long n = in.nextLong(), k = in.nextLong();
        // 定义数组a来装每个蛋糕的美味值
        long[] a = new long[(int) n];
        // 将美味值写入数组
        for (int i = 0; i < n; i ++) {
            a[i] = in.nextLong();
        }
        // 最后符合条件的美味值总和
        long res = 0;
        for (int i = 0; i < (1 << n); i++) {
            long sum = 0;
            for (int j = 0; j < n; j++) {
                // 如果二进制最后一位为1，说明被选中
                if (((i >> j) & 1) == 1) {
                    sum += a[j];
                }
            }
            // 选完一轮，进行比较
            if (sum < k) res = Math.max(res, sum);

        }
        System.out.println(res);
    }
}
